﻿<UserControl x:Class="CodeCounsel.SharePoint.RibbonDesigner.View.Group" 
                       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                       xmlns:v="clr-namespace:CodeCounsel.SharePoint.RibbonDesigner.View"
                       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                       xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                       xmlns:t="clr-namespace:CodeCounsel.SharePoint.RibbonDesigner.View.TypeConverters"
                       xmlns:a="clr-namespace:CodeCounsel.SharePoint.RibbonDesigner.View.AttachedBehaviors"
                       mc:Ignorable="d" 
                       Padding="9,0,0,0"
                       Background="Transparent"
                       a:VisualFocusManager.IsSelectable="True"
                       a:VisualFocusManager.FocusVisualStyle="{DynamicResource focusWithDragHandle}">
    <UserControl.Resources>
        <t:ResourceConverter x:Key="resourceConverter" />
    </UserControl.Resources>
    <StackPanel Orientation="Horizontal">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <ContentControl Grid.Row="0" Grid.Column="0">
                <ContentControl.Content>
                    <ItemsControl ItemsSource="{Binding Sections}" 
                                  Focusable="False">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Horizontal" />
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                    </ItemsControl>
                </ContentControl.Content>
                <ContentControl.Style>
                    <Style TargetType="{x:Type ContentControl}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsPopup}" Value="true">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate>
                                            <StackPanel>
                                                <RadioButton x:Name="CheckBox" GroupName="Popup">
                                                    <RadioButton.Template>
                                                        <ControlTemplate>
                                                            <Rectangle Fill="Green" Height="32" Width="32" Margin="2"
                                                                HorizontalAlignment="Center" VerticalAlignment="Center" />
                                                        </ControlTemplate>
                                                    </RadioButton.Template>
                                                </RadioButton>
                                                <Popup IsOpen="{Binding ElementName=CheckBox, Path=IsChecked}"
                                                       PlacementTarget="{Binding ElementName=CheckBox}">
                                                    <Border Background="White" BorderBrush="#898d92" BorderThickness="1">
                                                        <ItemsControl ItemsSource="{Binding Sections}" Focusable="False">
                                                            <ItemsControl.ItemsPanel>
                                                                <ItemsPanelTemplate>
                                                                    <StackPanel Orientation="Horizontal" />
                                                                </ItemsPanelTemplate>
                                                            </ItemsControl.ItemsPanel>
                                                        </ItemsControl>
                                                    </Border>
                                                </Popup>
                                            </StackPanel>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ContentControl.Style>
            </ContentControl>
            <Grid Grid.Row="1" Grid.Column="0">
                <TextBox HorizontalAlignment="Center" VerticalAlignment="Center"
                         Text="{Binding Title, Converter={StaticResource resourceConverter}}">
                    <TextBox.Style>
                        <Style TargetType="{x:Type TextBox}">
                            <Setter Property="HorizontalAlignment" Value="Center" />
                            <Setter Property="VerticalAlignment" Value="Center" />
                            <Setter Property="Margin" Value="0" />
                            <Setter Property="Background" Value="Transparent" />
                            <Setter Property="Cursor" Value="Hand" />
                            <Setter Property="BorderThickness" Value="0" />
                            <Style.Triggers>
                                <Trigger Property="IsFocused" Value="True">
                                    <Trigger.Setters>
                                        <Setter Property="Background" Value="White" />
                                        <Setter Property="Cursor" Value="IBeam" />
                                    </Trigger.Setters>
                                </Trigger>
                                <Trigger Property="Text" Value="">
                                    <Trigger.Setters>
                                        <Setter Property="MinWidth" Value="50" />
                                        <Setter Property="Background" Value="White" />
                                        <Setter Property="Cursor" Value="IBeam" />
                                    </Trigger.Setters>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </TextBox.Style>
                </TextBox>
            </Grid>
        </Grid>
        <Rectangle Width="1" Stroke="Gray" />
    </StackPanel>
</UserControl>
